import random

# 

f =  open("data_init.sql","a",encoding='utf8')
f.write("USE market;\n")


def generate_bussiness(file): # 10,0000
    for i in range(100000):
        index = i + 1
        f.write( "INSERT INTO businesses(b_name,in_come) VALUES (\"{0}\",{1});\n".format( "{0}_busi_name".format(index),random.randint(1,100000) ) );
    return


def generate_carts(file):

    return


def generate_goods(file): # 100,0000
    for i in range(1000000):
        index = i + 1
        f.write( "INSERT INTO goods(g_name,_weight,_description) VALUES (\"{0}\",{1},\"{2}\");\n".format( "{0}_good_name".format(index),random.randint(1,100000)%100,"this is good {0}_good_name.".format(index) ) )
    return


def generate_order_goods(file):

    return


def generate_orders(file):
    return


def generate_pays(file): #20,0000
    for i in range(2):
        for j in range(100000):
            f.write("INSERT INTO pays(platform,assets,userID) VALUES (\"{0}\",{1},\"{2}\");\n".format(
                ("支付宝" if i == 0 else "微信"), random.randint(1, 100000),
                100000-j))
    return


def generate_sells(file): # 初始化商家售卖商品, 每个商家10-20件商品, 不重复, 售价随机.
    for i in range(1,100001):
        good_num = random.randint(10,20)
        good_list = random.sample(range(1,1000001),good_num)
        for j in range(good_num):
            f.write("INSERT INTO sells(goodID,busiID,price) VALUES (\"{0}\",{1},\"{2}\");\n".format(
                good_list[j], i, random.randint(1,100000)))
    return


def generate_transitions(file):
    return


def generate_users(file): # 10,0000
    for i in range(2):
        for j in range(100000):
            f.write("INSERT INTO users(u_name) VALUES (\"{0}\");\n".format("{0}_user_name".format(j+1)))
    return

generate_bussiness(f)
generate_goods(f)
generate_pays(f)
generate_users(f)
generate_sells(f)
